<template>
  <div id="addressedit">
    <van-nav-bar
      title="编辑地址"
      left-text="返回"
      right-text=""
      left-arrow
      @click-left="onClickLeft"
      @click-right="onClickRight"
    />
    <van-address-edit
      :show-area="false"
      show-delete
      show-search-result
      :address-info="{
        name: this.$route.query.name,
        tel: this.$route.query.tel,
        addressDetail: this.$route.query.address,
      }"
      @save="onSave"
      @delete="onDelete"
    />
  </div>
</template>

<script>
import { Toast } from "vant";
export default {
  data() {
    return {};
  },
  mounted() {
    console.log(this.$route.query);
  },
  methods: {
    onClickLeft() {
      Toast("返回");
      this.$router.go(-1);
    },
    onClickRight() {
      Toast("按钮");
    },
    onSave(item) {
      Toast("修改地址成功!");
      this.$store.commit("addressedit", {
        userid: localStorage.getItem("id"),
        addressid: this.$route.query.addressid,
        address: item.addressDetail,
        phone: item.tel,
        tel: item.tel,
        name: item.name,
      });
      this.$router.go(-1);
    },
    onDelete() {
      Toast("删除地址成功");
      this.$store.commit("addressdel", this.$route.query);
      this.$router.go(-1);
    },
  },
};
</script>

<style>
</style>